package frank.zou.study.sample.in.persuit.of.quiality;

import org.jbehave.core.Block;
import org.jbehave.core.Ensure;
import org.jbehave.core.mock.UsingMatchers;

public class StackBehavior {

	private static final UsingMatchers m = new UsingMatchers(){};
	private Stack<String> stStack;

	public void setUp() {
		stStack = new Stack<String>();
	}

	public void shouldThrowExceptionUponNullPush() throws Exception {

		Ensure.throwsException(RuntimeException.class, new Block() {
			public void run() throws Exception {
				stStack.push(null);
			}
		});
	}

	public void shouldThrowExceptionUponPopWithoutPush() throws Exception {
		Ensure.throwsException(RuntimeException.class, new Block() {
			public void run() throws Exception {
				stStack.pop();
			}
		});
	}

	public void shouldPopPushedValue() throws Exception {
		stStack.push("frank");
		Ensure.that(stStack.pop(), m.is("frank"));
	
	}

	public void shouldPopSecondPushedValueFirst() throws Exception {
		stStack.push("frank");
		stStack.push("zou");
		Ensure.that(stStack.pop(), m.is("zou"));
	}
	
	public void shouldPopInReverseOrder() throws Exception { 
		stStack.push("1");
		stStack.push("2");
		Ensure.that(stStack.pop(), m.is("2"));
		Ensure.that(stStack.pop(), m.is("1"));
	}

	public void shouldLeaveValueOnStackAfterPeep() throws Exception {
		stStack.push("frank");
		Ensure.that(stStack.peak(), m.is("frank"));
		Ensure.that(stStack.pop(), m.is("frank"));
	}

	public void shouldReturnNullOnPeakWithoutPush() { 
		Ensure.that(stStack.peak(), m.is(null));
	}
}
